<?php
namespace app\admin\service; 
class ShopConfigService
{
    public function index($filter)
    {
        
        $shopConfig = model('ShopConfig');
        $where = [
		
        ];
        $join = [
            
        ];

        $field = 'a.*';
		$where['a.delete_time'] = 0 ;
 
        //条件查询
        $startTime = empty($filter['start_time']) ? 0 : strtotime($filter['start_time']);
        $endTime   = empty($filter['end_time']) ? 0 : strtotime($filter['end_time']);
        if (!empty($startTime) && !empty($endTime)) {
            $where['a.create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['a.create_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['a.create_time'] = ['<= time', $endTime];
            }
        }
        
        $keyword = empty($filter['keyword']) ? '' : $filter['keyword'];
        if (!empty($keyword)) {
            $where['a.shop_name'] = ['like', "%$keyword%"];
        }
        
        $shopConfig = $shopConfig->where($where)->join($join)->alias('a')->field($field)->paginate(10);
        return $shopConfig;
    
    }
    public function add($shopConfig){
        $shopConfigModel = model('ShopConfig');
        $shopConfig['vip_score_y'] = 0.00;
        return $shopConfigModel ->allowField(true)->save($shopConfig);
    }
    public function checkVipNo($vip){
        $vipInfo = model('TbVipInfo');
        return  $vipInfo->where('vip_no', $vip)->field('isid')->find();
    }
}

